import { timeFormat } from './time'

type LogParams = Parameters<typeof console.log>

export class Logger {
  static log(level: string, ...args: LogParams) {
    const timestamp = timeFormat(new Date())
    const logPre = `[${timestamp}] [${level}]`

    switch (level) {
      case 'DEBUG':
        console.debug(logPre, ...args)
        break
      case 'INFO':
        console.info(logPre, ...args)
        break
      case 'WARN':
        console.warn(logPre, ...args)
        break
      case 'ERROR':
      case 'FATAL':
        console.error(logPre, ...args)
        break
      default:
        console.log(logPre, ...args)
    }
  }

  static debug(...args: LogParams) {
    this.log('DEBUG', ...args)
  }

  static info(...args: LogParams) {
    this.log('INFO', ...args)
  }

  static warn(...args: LogParams) {
    this.log('WARN', ...args)
  }

  static error(...args: LogParams) {
    this.log('ERROR', ...args)
  }

  static fatal(...args: LogParams) {
    this.log('FATAL', ...args)
  }
}
